define("register",["jquery","jquery-validate","jquery.idcode"],function () {
    return {
        register:function(){
            $.idcode.setCode()
            $("#idcode_change").on("click",function () {
                $.idcode.setCode()
            })
            $("form").validate({
                rules : {
                    telphone : {
                        required : true,
                        rangelength : [11,11],
                        remote : {
                            url : "http://127.0.0.1/mailegou/server/isRegister.php",
                            type : "post",
                            data : {"telphone" : function(){return $("[name=telphone]").val();}}
                        }
                    },
                    upwd:{
                        required : true,
                        rangelength : [6, 20],
                    },
                    upwd1:{
                        required : true,
                        equalTo:"#upwd"
                    }
                },
                messages : {
                    telphone : {
                        required : "手机号码不能为空",
                        rangelength : "您输入的手机号码格式错误，请重新输入!",
                        remote:"用户名已存在",
                    },
                    upwd:{
                        required : "密码不能为空",
                        rangelength : "密码的长度为{0}到{1}",
                    },
                    upwd1:{
                        required : "密码不能为空",
                        equalTo:"俩次输入的密码必须一致"
                    }

                },
                submitHandler:function(){
                    console.log($("form")[0].telphone.value);
                    var formdate={
                        "telphone":$("form")[0].telphone.value,
                        "upwd":$("form")[0].upwd.value
                    }
                    console.log(formdate);
                    console.log($("#agree")[0].checked);
                    if($("#agree")[0].checked){
                        $.ajax({
                            url:"http://127.0.0.1/mailegou/server/register.php",
                            data:formdate,
                            type:"post"
                        }).then(function (res) {
                            console.log(res);
                            if(confirm("是否登录"))
                            {
                                document.location.assign("login.html")
                            }
                        })
                    }
                    return false
                }
            })
        }
    }
})